/*!
 * \file iptools_parse_iprange.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "frstr.h"
#include "conntrack.h"
#include "frct_comm.h"

#include "apmtest_comm.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    char *dotted = (char *)frstrdup((char *)("192.168.1.1-192.168.1.10"));
    u_int min_ip = 0;
    u_int max_ip = 0;

    iptools_parse_iprange(dotted, &min_ip, &max_ip);

    frfree(dotted);
    CU_ASSERT_EQUAL(min_ip,16885952);
    CU_ASSERT_EQUAL(max_ip,167880896);
}

static void __case2(void)
{
    char *dotted = NULL;
    u_int min_ip = 0;
    u_int max_ip = 0;

    iptools_parse_iprange(dotted, &min_ip, &max_ip);

    frfree(dotted);
    CU_ASSERT_EQUAL(min_ip,0);
    CU_ASSERT_EQUAL(max_ip,0);
}

static void __case3(void)
{
    char *dotted = (char *)frstrdup((char *)("192.168.1.1"));
    u_int min_ip = 0;
    u_int max_ip = 0;

    iptools_parse_iprange(dotted, &min_ip, &max_ip);

    frfree(dotted);
    CU_ASSERT_EQUAL(min_ip,16885952);
    CU_ASSERT_EQUAL(max_ip,16885952);
}

int add_suite_iptools_parse_iprange(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frsutl iptools_parse_iprange()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);


    return FR_SUCC;
}
